local Class = require('lua.lang.Class')

--- @generic T
--- @class Stack : Class
--- @field list T[]
--- @field top number
local Stack = Class {}

--- @generic T
--- @return Stack
function Stack:new()
	--- @type Stack
	local o = {}
	o.top = 0
	o.list = {}
	return setmetatable(o, Stack)
end

--- @generic T
--- @param o T
--- @return T
function Stack:push(o)
	local top = self.top + 1
	self.top = top
	self.list[top] = o
	return o
end

--- @generic T
--- @return T
function Stack:pop()
	local top = self.top
	local o = self.list[top]
	self.list[top] = nil
	self.top = top - 1
	return o
end

--- @generic T
--- @return boolean
function Stack:isNotEmpty()
	return #self.list > 0
end

return Stack